//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.kun.portal.webframe.controller;

import com.kun.portal.webframe.po.AppointmentPo;
import com.kun.portal.webframe.po.FlightPlanePo;
import com.kun.portal.webframe.po.FwUserPo;
import com.kun.portal.webframe.service.AppointmentService;

import javax.servlet.http.HttpSession;

import com.kun.portal.webframe.service.FlightPlaneService;
import com.kun.portal.webframe.util.Status;
import com.kun.portal.webframe.util.UserSessionUtil;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.format.datetime.DateFormatter;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping({"/api/appointment"})
public class AppointmentController {
    private static final Logger LOG = LoggerFactory.getLogger(FwUserController.class);
    @Autowired
    private AppointmentService appointmentService;

    @Autowired
    private FlightPlaneService flightPlaneService;
    @InitBinder
    public void intDate(WebDataBinder dataBinder){
        dataBinder.addCustomFormatter(new DateFormatter("yyyy-MM-dd"));
    }
    @RequestMapping(
            value = {"/addAppointment"},
            method = {RequestMethod.POST},
            produces = {"application/json"}
    )
    @ResponseBody
    public AppointmentPo addAppointment(@RequestBody AppointmentPo appointmentPo, HttpSession session) {
        appointmentPo.setEnterDate(new Date());

        FwUserPo user = UserSessionUtil.getCurrentUser(session);
        return appointmentService.addAppointment(appointmentPo ,user);
    }
    @RequestMapping(
            value = {"/editAppointment"},
            method = {RequestMethod.POST},
            produces = {"application/json"}
    )
    @ResponseBody
    public AppointmentPo updateAppointment(@RequestBody AppointmentPo appointmentPo, HttpSession session) {
        appointmentPo.setUpdateDate(new Date());
        FwUserPo user = UserSessionUtil.getCurrentUser(session);
        appointmentPo.setUpdatePerson(user);
        return appointmentService.editAppointment(appointmentPo,user);
    }
    @RequestMapping(
            value = {"/saveAppointmentAndFlight"},
            method = {RequestMethod.POST},
            produces = {"application/json"}
    )
    @ResponseBody
    public AppointmentPo saveAppointmentAndFlight(@RequestBody AppointmentPo appointmentPo, HttpSession session) {
//        appointmentPo.setUpdateDate(new Date());
        FwUserPo user = UserSessionUtil.getCurrentUser(session);
//        appointmentPo.setUpdatePerson(user);
        return appointmentService.saveAppointmentAndFlight(appointmentPo,user);
    }

    @RequestMapping(
            value = {"/publishAppointmentAndFlight"},
            method = {RequestMethod.POST},
            produces = {"application/json"}
    )
    @ResponseBody
    public AppointmentPo publishAppointmentAndFlight(@RequestBody AppointmentPo appointmentPo, HttpSession session) {
        FwUserPo user = UserSessionUtil.getCurrentUser(session);
        return appointmentService.publishFlightPlane(appointmentPo,user);
    }
    @RequestMapping(
            value = {"/throughAuditAppointmentAndFlight"},
            method = {RequestMethod.POST},
            produces = {"application/json"}
    )
    @ResponseBody
    public AppointmentPo throughAuditAppointmentAndFlight(@RequestBody AppointmentPo appointmentPo, HttpSession session) {
        FwUserPo user = UserSessionUtil.getCurrentUser(session);
        return appointmentService.throughAudit(appointmentPo,user);
    }


    @RequestMapping(
            value = {"/passAppointment"},
            method = {RequestMethod.POST},
            produces = {"application/json"}
    )
    @ResponseBody
    public AppointmentPo passAppointment(@RequestBody AppointmentPo appointmentPo, HttpSession session) {
        appointmentPo.setUpdateDate(new Date());
        appointmentPo.setOrderStatus(Status.UN_EFFECTIVE);
        FwUserPo user = UserSessionUtil.getCurrentUser(session);
        appointmentPo.setExaminePerson(user);
        return appointmentService.passAppointment(appointmentPo,user);
    }

    @RequestMapping(
            value = {"/getAppointments"},
            method = {RequestMethod.GET},
            produces = {"application/json"}
    )
    @ResponseBody
    public Page<AppointmentPo> getAppointments(@RequestParam(required = false) String appoUnit , @RequestParam(required = false)String appoPhoneNum, @RequestParam(required = false)Date startDate,
                                               Date endDate,String status,String importOrExport, Pageable pageable, HttpSession session) {
        return appointmentService.queryNew(pageable,appoUnit,appoPhoneNum,startDate,endDate,status,importOrExport);
    }

    @RequestMapping(
            value = {"/findAppointment"},
            method = {RequestMethod.GET},
            produces = {"application/json"}
    )
    @ResponseBody
    public Page<AppointmentPo> findAppointment(@RequestParam(required = false) String appoUnit , @RequestParam(required = false)String appoPhoneNum, @RequestParam(required = false)Date startDate,
                                               Date endDate,String status,String importOrExport, Pageable pageable, HttpSession session) {
        return appointmentService.query(pageable,appoUnit,appoPhoneNum,startDate,endDate,status,importOrExport);
    }


    @RequestMapping(
            value = {"/findAppointmentFlightPlane"},
            method = {RequestMethod.GET},
            produces = {"application/json"}
    )
    @ResponseBody
    public Page<AppointmentPo> findAppointmentFlightPlane(@RequestParam(required = false) String flightInfoId ,@RequestParam(required = false) Date exceptDateS,@RequestParam(required = false) Date exceptDateE,
                                                          @RequestParam(required = false)  Date estimatedTimeS, @RequestParam(required = false)  Date estimatedTimeE, String importOrExport,  Pageable pageable, HttpSession session) {
        return appointmentService.queryAppointmnetPlane(pageable,flightInfoId,exceptDateS,exceptDateE,estimatedTimeS,estimatedTimeE,importOrExport);
    }


    @RequestMapping(
            value = {"/findAppointmentPublishedFlightPlane"},
            method = {RequestMethod.GET},
            produces = {"application/json"}
    )
    @ResponseBody
    public List<AppointmentPo> findAppointmentPublishedFlightPlane(@RequestParam(required = false) String flightInfoId ,@RequestParam(required = false) Date exceptDateS,@RequestParam(required = false) Date exceptDateE,
                                                          @RequestParam(required = false)  Date estimatedTimeS, @RequestParam(required = false)  Date estimatedTimeE, String importOrExport,  Pageable pageable, HttpSession session) {
        return appointmentService.queryAppointmentPublishedFlightPlane(pageable,flightInfoId,exceptDateS,exceptDateE,estimatedTimeS,estimatedTimeE,importOrExport);
    }

    @RequestMapping(
            value = {"/findAppointmentFlightPlaneNoPage"},
            method = {RequestMethod.GET},
            produces = {"application/json"}
    )
    @ResponseBody
    public List<AppointmentPo> findAppointmentFlightPlaneNoPage(@RequestParam(required = false) String flightInfoId ,@RequestParam(required = false) Date exceptDateS,@RequestParam(required = false) Date exceptDateE,
                                                          @RequestParam(required = false)  Date estimatedTimeS, @RequestParam(required = false)  Date estimatedTimeE, String importOrExport,  Pageable pageable, HttpSession session) {
        return appointmentService.queryAppointmnetPlaneNoPage(pageable,flightInfoId,exceptDateS,exceptDateE,estimatedTimeS,estimatedTimeE,importOrExport);
    }

    @RequestMapping(
            value = {"/findAppointmentAndFlightPlaneNoPage"},
            method = {RequestMethod.GET},
            produces = {"application/json"}
    )
    @ResponseBody
    public List<AppointmentPo> findAppointmentAndFlightPlaneNoPage(@RequestParam(required = false) String flightInfoId ,@RequestParam(required = false) Date exceptDateS,@RequestParam(required = false) Date exceptDateE,
                                                                @RequestParam(required = false)  Date estimatedTimeS, @RequestParam(required = false)  Date estimatedTimeE, String importOrExport,  Pageable pageable, HttpSession session) {
        return appointmentService.queryAppointmnetAndPlaneNoPage(pageable,flightInfoId,exceptDateS,exceptDateE,estimatedTimeS,estimatedTimeE,importOrExport);

    }

    @RequestMapping(
            value = {"/findVehicleOfAppointment"},
            method = {RequestMethod.GET},
            produces = {"application/json"}
    )
    @ResponseBody
    public Page<AppointmentPo> findAllvehicleOfAppo(@RequestParam(required = false) String appoUnit , @RequestParam(required = false)String appoName, @RequestParam(required = false)String appoPhoneNum, @RequestParam(required = false)Date appoDate,Pageable pageable) {
        System.out.print(appoUnit);
        return appointmentService.findAllvehicleOfAppo(pageable,appoUnit,appoName, appoPhoneNum,appoDate);

    }
    @RequestMapping(
            value = {"/findAllAppointOfSignin"},
            method = {RequestMethod.GET},
            produces = {"application/json"}
    )
    @ResponseBody
    public List<AppointmentPo> findAllAppointOfSignin(@RequestParam(required = true)String flightInfoId,String planeId, String originating,String destination,Date appoDate,String appProperty) {
        return appointmentService.findAllAppointOfSignin(flightInfoId,planeId,originating,destination,appoDate,appProperty);
    }

    @RequestMapping(
            value = {"/findAllAppoUnit"},
            method = {RequestMethod.GET},
            produces = {"application/json"}
    )
    @ResponseBody
    public List<AppointmentPo> findAllAppoUnit() {
        return appointmentService.findAllAppoUnit();
    }


    @RequestMapping(
            value = {"/transFormToFlightPlane"},
            method = {RequestMethod.POST},
            produces = {"application/json"}
    )
    @ResponseBody
    @Transactional
    public AppointmentPo transFormToFlightPlane(@RequestBody AppointmentPo appointmentPo, HttpSession session) {


        FwUserPo user = UserSessionUtil.getCurrentUser(session);
        return appointmentService.transFormToFlightPlane(appointmentPo,user);
    }


}